<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DeepClone</title>
</head>

<body>
    <script>
        function deepClone(obj) {
            return new Promise((resolve, reject) => {
                const { port1, port2 } = new MessageChannel();
                port1.postMessage(obj)
                port2.onmessage = (msg) => {
                    resolve(msg.data)
                }
            })
        }

        async function test() {
            const a = {
                a1: 123,
                a2: '456',
            }

            const b = await deepClone(a)
            console.log(b)
        }

        test()
    </script>
</body>

</html>